package com.wteam.controller;

import com.wteam.PoJo.DTO.cart;
import com.wteam.service.GoodsCartServicer;
import com.wteam.untils.MemberIdAndName;
import com.wteam.untils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@Api(tags = "购物模块")
@RequestMapping("/buy")
public class GoodcartController {

    @Autowired
    private GoodsCartServicer goodsCartServicer;

    @Autowired
    private MemberIdAndName memberIdAndName;

    /**
     *
     * @param goodid
     * @return
     */
    @ApiOperation(value = "添加购物车")
    @GetMapping("/addcart/{goodid}")
    @CacheEvict(value = "goods_cart", allEntries = true)
    @Validated
    public Result savecar(@PathVariable Integer goodid) {
        return goodsCartServicer.addcart(goodid);
    }

    /**
     *
     * @param page
     * @param pagesize
     * @return
     */
    @ApiOperation(value = "查看购物车")
    @GetMapping("/listcar/{page}/{pagesize}")
    @Cacheable(value = "goods_cart", key = "#page+'_'+#pagesize")
    @Validated
    public Result<List<cart>> listcar(@PathVariable Integer page, @PathVariable Integer pagesize) {
        return goodsCartServicer.listcar(page,pagesize);
    }

    /**
     *
     * @param goodid
     * @return
     */
    @ApiOperation(value = "删除购物车商品")
    @DeleteMapping("/deletecar/{goodid}")
    @CacheEvict(value = "goods_cart", allEntries = true)
    @Validated
    public Result listcar(@PathVariable @ApiParam("要删除的商品id") List<Integer>goodid) {
        return goodsCartServicer.deletegoodId(goodid);
    }








}
